package com.snail.controller;

import com.snail.model.dto.ManageQuesstionDto;
import com.snail.response.BaseResponse;
import com.snail.service.BizQuestionService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author ysc
 * @descrpiton
 * @date 2025/7/19 11:38
 **/
@RestController
@RequestMapping("/questionSimple")
@AllArgsConstructor
public class BizQuestionController {

    private final BizQuestionService bizQuestionService;
    // 新增
    @PostMapping
    public BaseResponse<?> addQuestion(@RequestBody ManageQuesstionDto dto) {
        return bizQuestionService.addQuestion(dto);
    }

    // 删除
    @DeleteMapping("/{id}")
    public BaseResponse<?> deleteQuestion(@PathVariable Long id) {
        return bizQuestionService.deleteQuestion(id);
    }

    // 修改
    @PutMapping("/{id}")
    public BaseResponse<?> updateQuestion(@PathVariable Long id, @RequestBody ManageQuesstionDto dto) {
        return bizQuestionService.updateQuestion(id, dto);
    }

    // 查询分页题目（可选类型筛选）
    @GetMapping("/list")
    public BaseResponse<?> listQuestions(@RequestParam(required = false) Integer questionType,
                                         @RequestParam(required = false) Integer questionTag,
                                         @RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer size) {
        return bizQuestionService.listQuestions(questionType, questionTag, page, size);
    }

    // 查询单题
    @GetMapping("/{id}")
    public BaseResponse<?> getQuestion(@PathVariable Long id) {
        return bizQuestionService.getQuestionById(id);
    }

}
